<?php 
class Gold_Cmage_Model_Sales_Order extends Mage_Sales_Model_Order
{
	/**
     * Retrieve order credit memo (refund) availability
     *
     * @return bool
     */
    public function canCreditmemo()
    {
        if ($this->hasForcedCanCreditmemo()) {
            return $this->getForcedCanCreditmemo();
        }

        if ($this->canUnhold() || $this->isPaymentReview()) {
            return false;
        }

        if ($this->isCanceled() || $this->getState() === self::STATE_CLOSED) {
            return false;
        }

        /**
         * if has not items to refund return false
         */
        if (count($this->getAllItems())) {
        	$toRefund = 0;
            foreach ($this->getAllItems() as $item)
            {
            	if($item->getQtyToRefund())
            	{
            		$toRefund += $item->getQtyToRefund();
            	}
            }
            if (!$toRefund)
            {
            	return false;
            }
        }

        if ($this->getActionFlag(self::ACTION_FLAG_EDIT) === false) {
            return false;
        }
        return true;
    }
    
	/**
     * Round up and cast specified amount to float or string
     *
     * @param string|float $amount
     * @param bool $asFloat
     * @return string|float
     */
    protected function _formatAmount($amount, $asFloat = false)
    {
         $amount = Mage::app()->getStore()->roundPrice($amount);
         return !$asFloat ? (string)$amount : $amount;
    }
}
?>